package com.ant.storage.controller;

import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.MonthlyDto;
import com.ant.storage.dto.MonthlySettlementDto;
import com.ant.storage.dto.PurchaserRecordDto;
import com.ant.storage.dto.RecordDto;
import com.ant.storage.service.IPurchaserRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author melon
 * @since 2022-04-13
 */
@RestController
@RequestMapping("/purchaser-record")
@Api(tags = "报销接口")
public class PurchaserRecordController {

    @Autowired
    private IPurchaserRecordService recordService;

    @ApiOperation(value = "采购单报销申请")
    @PostMapping("/settlement")
    private ResultVo settlement(@RequestBody PurchaserRecordDto purchaserRecordDto, BindingResult bindingResult)   {
      return recordService.purchaserRecordSettlement(purchaserRecordDto, bindingResult);
    }

    @ApiOperation(value = "小程序采购单合并报销")
    @PostMapping("/mergeSettlement")
    public ResultVo mergeSettlement(@RequestBody PurchaserRecordDto dto, BindingResult bindingResult) {
        return recordService.mergeSettlement(dto,bindingResult);
    }

    @ApiOperation(value = "小程序采购单合并报销22")
    @PostMapping("/mergeSettlements")
    public ResultVo mergeSettlements(@RequestBody PurchaserRecordDto dto, BindingResult bindingResult) {
        return recordService.mergeSettlements(dto,bindingResult);
    }

    /**
     * 获取采购单结算申请列表
     * @param dto
     * @return
     */
    @ApiOperation(value = "获取采购单结算申请列表")
    @GetMapping("/getApplySettlement")
    private ResultPage getApplySettlement(PurchaserRecordDto dto) {
        return ResultPage.success("获取成功", recordService.getApplySettlement(dto));
    }

    @ApiOperation(value = "财务通过id获取非月结单结算单详情")
    @GetMapping("/getApplySettlementsById/{id}/{purchaseType}")
    private ResultVo getApplySettlementsById(@PathVariable(value = "id", required = false) Integer id,
                                             @PathVariable(value = "purchaseType", required = false) String purchaseType) {
        return recordService.getApplySettlementsById(id,purchaseType);
    }

    @ApiOperation(value = "财务冲账申请通过")
    @PostMapping("/getApplyAdopt")
    private ResultVo getApplyAdopt(@RequestBody PurchaserRecordDto dto) {
        return recordService.getApplyAdopt(dto);
    }


    @ApiOperation(value = "申请人获取供应商月结结算信息")
    @GetMapping("/getSupplierInformation")
    private ResultPage getSupplierInformation(MonthlyDto dto) {
        return ResultPage.success("查询成功", recordService.getSupplierInformation(dto));
    }

    @ApiOperation(value = "财务获取月结申请")
    @GetMapping("/getMonthlyApplySettlement")
    private ResultPage getMonthlyApplySettlement(PurchaserRecordDto dto) {
        return ResultPage.success("获取成功", recordService.getMonthlyApplySettlement(dto));
    }


    @ApiOperation(value = "财务通过月结申请同意结算")
    @PostMapping("/MonthlySettlementAdopt")
    private ResultVo MonthlySettlementAdopt(@RequestBody MonthlySettlementDto dto) {
        return recordService.MonthlySettlementAdopt(dto);
    }


    @ApiOperation(value = " 通过id获取结算单详情")
    @GetMapping("/getSettlementsById/{id}")
    private ResultVo getSettlementsById(@PathVariable(value = "id", required = false) Integer id) {
        return recordService.getSettlementsById(id);
    }

    @ApiOperation(value = "月结申请提交")
    @PostMapping("/MonthlySettlementSave")
    private ResultVo MonthlySettlementSave(@RequestBody PurchaserRecordDto purchaserRecordDto,
                                           BindingResult bindingResult) {
        return recordService.MonthlySettlementSave(purchaserRecordDto, bindingResult);
    }

    @ApiOperation(value = "小程序获取报销记录")
    @GetMapping("/getSettlementRecord")
    public ResultPage getSettlementRecord(RecordDto dto) {
        return  ResultPage.success("",recordService.getSettlementRecord(dto));
    }

    @ApiOperation(value = "重复钉钉")
    @GetMapping("/rsendDingTalks/{id}/{uid}")
    private ResultVo rsendDingTalks(@PathVariable("id") Integer id,@PathVariable("uid") Integer uid) throws Exception {
        return ResultVo.success("获取成功", recordService.RsendDingTalks(id,uid));
    }

    @ApiOperation(value = "同步钉钉")
    @GetMapping("/syncDingTalk/{id}")
    private ResultVo syncDingTalk(@PathVariable("id") Integer id) throws Exception {
        return  recordService.syncDingTalk(id);
    }



    @ApiOperation(value = " 通过id获取结算单详情")
    @GetMapping("/getPurchaserRecordById/{id}")
    private ResultVo getPurchaserRecordById(@PathVariable(value = "id", required = false) Integer id) {
        return recordService.getPurchaserRecordById(id);
    }


    @ApiOperation(value = "撤销申请")
    @GetMapping("/revoke/{id}")
    private ResultVo revoke(@PathVariable(value = "id", required = false) Integer id) {
        return recordService.revoke(id);
    }
}
